  // JavaScript Document
  import { hashHistory } from 'dva/router';
  import { query } from '../../../services/service';
  import request from '../../../utils/request';


  export default {
	namespace: 'users',

	state: {
	  list: [],
	  total: null,
	  loading: false,
	  current: null,
	  currentItem: {},
	  modalVisible: false,
	  modalType: 'create',
    visible: false,

	},

	subscriptions: {
	  setup({ dispatch, history }) {
		history.listen(location => {
		  if (location.pathname === '/a') {
			dispatch({
			  type: 'query',
			  payload: {}
			});
		  }
		});
	  },
	},
	  effects: {
		   *query({ payload }, { select, call, put }) {
		yield put({ type: 'showLoading' });
		const { data } = yield call(query,{...payload});
    console.log('wb'+data);
		if (data) {
		  yield put({
			type: 'querySuccess',
			payload: {
			  list: data.data,
			  total: data.page.total,
			  current: data.page.current
			}
		  });
		}
  },
  *modelSubmit({ payload }, { select, call, put }){
    yield put({  type: 'hideModal'});

  },
  *ModalOpen({ payload }, { select, call, put }){
    yield put({  type: 'showModal'});
 },
 *modalHide({ payload }, { select, call, put }){
   yield put({  type: 'hideModal'});
},
		  *create(){},
		  *'delete'(){},
		  *update(){},
	  },



	  reducers: {
		   showLoading(state, action){
			return { ...state, loading: true };
	 	    },





		  querySuccess(state, action){
     				 return {...state, ...action.payload, loading: false};
   		  },
		  createSuccess(){},
		  deleteSuccess(){},
		  updateSuccess(){},
      //控制modal弹框的显示--改变visible状态 bool值
      showModal(state, action){
        return { ...state, visible: true };
      },
      hideModal(state, action){
        return { ...state, visible: false };
      },
	  }
  }
